<template>
	<view>
		<view class="search-box">
			<my-search @click="gotosearch()"></my-search>
		</view>
		<!--轮播图区域-->
		<swiper :indicator-dots="true" 	:autoplay="true" :interval="3000" :duration="1000"  :circular="true">
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id" open-type="navigate">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
	</view>
	<view class="nav-list">
		<view class="nav-item" v-for="(item,i) in navList" :key="i">
			<image :src="item.image_src" class="nav-img" mode="widthFix" @click="navClickHandler(item)" ></image>
			<!-- <text>{{item.name}}</text> -->
		</view>
	</view>
	<view class="floor-List">
		<view class="floor-item" v-for="(item,i) in floorList" :key="i">
			<image :src="item.floor_title.image_src" class="floor-title"></image>
			<view class="floor-img-box" >
			
				<navigator class="left-img-box" :url="'/subpkg/goods_list/goods_list?'+item.product_list[0].query" open-type="navigate"  >
					<image  :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}"  mode="widthFix"> </image>
				</navigator>
				<view class="right-img-box">
					<block  v-for="(item2,index) in item.product_list" :key="index">
						<navigator class="right-img-item"  open-type="navigate" :key="index" :url="'/subpkg/goods_list/goods_list?'+item2.query" v-if="index!==0" >
							<image  :src="item2.image_src" :style="{width:item2.image_width+'rpx'}" mode="widthFix"  > </image>
						</navigator>
					</block>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				swiperList:[],
				navList:[],
				floorList:[]
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},methods: {
			async getSwiperList()
			{
				const res=await uni.$http.get('/api/public/v1/home/swiperdata')
				if(res.statusCode!==200)
				{
					return uni.$showMsg();
				}
				this.swiperList=res.data.message;
			},
			async getNavList()
			{
				const res=await uni.$http.get('/api/public/v1/home/catitems')
				if(res.statusCode!==200)
				{
					return uni.$showMsg();
				}
				this.navList=res.data.message;
			},
			async getFloorList()
			{
				const res=await uni.$http.get('/api/public/v1/home/floordata')
				if(res.statusCode!==200)
				{
					return uni.$showMsg();
				}
				this.floorList=res.data.message;
				for(var x=0;x<this.floorList.length;x++)
				{
					for(var i=0;i<this.floorList[x].product_list.length;i++)
					{
						var urls=this.floorList[x].product_list[i].navigator_url.split("?");
						this.floorList[x].product_list[i].query=urls[1]
						
					}
					
				}
			
			} ,
			
		 	navClickHandler(item)
			{
				console.log(item.name)
				if(item.name=='分类')
				{
					uni.switchTab({
						url:"/pages/cate/cate"
					})
				}
			} ,
			gotosearch()
			{
				
			}
			
		}
		
	}
</script>

<style lang="scss">
swiper
{
	height: 330rpx;
	.swiper-item, image{
		height: 100%;
		width: 100%;
	}
}

.nav-list
{
	display: flex;
	justify-content: space-around;
	margin: 15px 0px;
	align-items: center;
	.nav-item
	{
		justify-content: space-evenly;
		.nav-img
		{
			width: 128rpx;
			height: 140rpx;
		}
	}
}
.floor-title
{
	height: 60rpx;
	width: 100%;
}

.right-img-box{
	display: flex;
	flex-direction: row;
	/* 子元素 两侧的子元素贴两边 , 其它元素平分 剩余空间 */
	justify-content: space-evenly;
	/* 设置自动换行 */
	flex-wrap: wrap;
	
}
.floor-img-box 
{
	display: flex;
	padding-left: 10rpx;
}
.search-box
{
	//设置定位效果为“吸顶”
	position: sticky;
	//吸顶位置
	top:0;
	// 提高层级，防止轮换播图覆盖
	z-index:999
}

</style>
